/**
 * 
 */
package com.wissen.giskard.client.payroll.widget;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.wissen.giskard.client.data.SalaryDTO;
import com.wissen.giskard.client.payroll.controller.PayRollController;
import com.wissen.giskard.client.payroll.observer.PayRollObserver;
import com.wissen.giskard.client.payroll.services.ColumnData;
import com.wissen.giskard.client.widget.DynamicTableWidget;

/**
 * @author Swapnil Sonawane
 *
 * @created date :09-Aug-2010
 */


public class LoadTable extends Composite implements PayRollObserver{
	
	
	 SalaryDTO salaryDto = new SalaryDTO();
	 
	 String[] header ;
	 
	 List<ColumnData[]> data = new ArrayList<ColumnData[]>();
	 
	 VerticalPanel tablePanel = new VerticalPanel();
	 
	 ColumnData[] columns;
	
	public LoadTable()
	{
		PayRollController.getInstance().addPayRollObserver(this);
		init();
		
		tablePanel.setSize("400px", "500px");
		initWidget(tablePanel);
		
	}

	
	private void init()
	{
		PayRollController.getInstance().displayTable();
	}
@Override
public void notifyTableDisplayFail(String msg) {
	tablePanel.add(new Label(msg));	
}
@Override
public void notifyTableDisplaySucceeded( List<SalaryDTO> columnData) {
	try{
		
		header =salaryDto.getColumnHeader();
		for(SalaryDTO salaryDto:columnData)
		{
			columns=salaryDto.getColumnData();
			data.add(columns);
		}
		tablePanel.add(new DynamicTableWidget(header, data));
		
	}catch (Exception e) {
		e.printStackTrace();
	}
	
}
	
	

}
